package wwy.Controller;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import wwy.Common.LogicController;
import wwy.Dao.AddressDao;
import wwy.Dto.AddressDto;
import wwy.Service.AddressService;
import wwy.entity.Address;

import java.util.List;

@RestController
@Tag(name = "地址服务")
@RequestMapping("/address")
@RefreshScope
public class AddressController extends LogicController<AddressService, AddressDao, Address, Long> {
    public AddressController(@Autowired AddressService service) {
        super(service);
    }
    @GetMapping("/getUserAddress/{user_id}")
    public List<AddressDto> getUserAddress(@PathVariable("user_id") Long userId) {
        return service.findUserAddressByUser_Id(userId);
    }
    @PutMapping("/updateAddress")
    public void updateAddress(@RequestBody AddressDto address) {
        service.update(address);
    }
    @PostMapping("/addAddress")
    public void addAddress(@RequestBody AddressDto address) {
        service.add(address);
    }
    @DeleteMapping("/deleteAddress")
    public void deleteAddress(@RequestParam(value = "id") Long id) {
        service.delete(id);
    }
}
